<template>
    <div>
        <div class="container">
            <div class="my_analysis">
                <div class="return_button"  @click="this.$router.back()">
                    <img src="@/assets/img/返回箭头1.png" width="35" alt="">
                    <p class="return_p">返回</p>
                </div>
                <div class="my_analysis_title">
                    <strong>| </strong>
                    <p>批量处理展示</p>
                    <div v-show="isShow">
                        <div >————如果您对批量处理展示的结果不满意可以返回，重新选择相应算法</div>
                    </div>
                    <div v-show="!isShow">
                        <div >————您可以点击"查看详情"在线查看客户报告，也可以导出下载到本地</div>
                    </div>
                    <el-button @click="download()" style="margin-left: 380px" type="success">导出报告</el-button>
                </div>
                <div class="report_container1">
                    <div v-for="item in users"
                         class="report_container2" >
                        <div class="batch_conten1">
                            <img src="@/assets/img/用户1.png" style="margin-left: 8px" width="35" alt="">
                            <p class="img_p">{{item.name}}</p><br>
                            <div class="batch_conten1_date">
                                <i class="el-icon-date batch_icon"></i>
                                <p class="img_p">日期</p>
                                <p >{{item.time.substring(0, 10)}}</p>
                            </div>
                        </div>
                        <div v-show="isShow" class="batch_conten2">
                            <div class="original">
                                <transition-group name="fade" ppear tag="div">
                                    <el-image
                                            v-for="item1 in item.originalUrlList"
                                            :key="item1.id"
                                            class="my_analysis_image"
                                            style="width: 100px; height: 100px"
                                            :src="item1.url"
                                            :preview-src-list="[item1.url]"
                                    >
                                    </el-image>
                                </transition-group>
                            </div>
                            <div class="pretreatment">
                                <transition-group name="fade" ppear tag="div">
                                    <el-image
                                            v-for="item1 in item.pretreatmentUrlList"
                                            :key="item1.id"
                                            class="my_analysis_image"
                                            style="width: 100px; height: 100px"
                                            :src="item1.url"
                                            :preview-src-list="[item1.url]"
                                    >
                                    </el-image>
                                </transition-group>
                            </div>

                        </div>
                        <div v-show="!isShow" class="batch_conten2">
                            <div class="original">
                                <transition-group name="fade" ppear tag="div">
                                    <el-image
                                            v-for="item1 in item.pretreatmentUrlList"
                                            :key="item1.id"
                                            class="my_analysis_image"
                                            style="width: 100px; height: 100px"
                                            :src="item1.url"
                                            :preview-src-list="[item1.url]"
                                    >
                                    </el-image>
                                </transition-group>
                            </div>
                            <div class="summary">
                                <transition-group name="fade" ppear tag="div">
                                    <div key="1" class="summary-header">{{common.header}}</div>
                                    <div key="2" class="summary-content">{{item.textSummary}}</div>
                                </transition-group>
                            </div>
                            <transition name="fade" ppear tag="div">
                            <div @click="viewDetails(item.report)" class="summary-footer">{{common.footer}}</div>
                            </transition>
                        </div>
                    </div>
                    <div class="image_footer">
                        <div v-show="this.isShow">
                            <el-button @click="this.isShow = !isShow" class="my_button_size" type="primary">下 一 页</el-button>
                        </div>
                        <div v-show="!this.isShow">
                            <el-button @click="this.isShow = !isShow" class="my_button_size" type="primary">上 一 页</el-button>
                            <el-button @click="complete()" class="my_button my_button_size" type="primary">完 成</el-button>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>

</template>

<script>
    import api from '@/api'
    export default {
        name: "BatchAnalysis",
        data() {
            return {
                users:[
                    {
                        id:"",
                        name: "张三",
                        time: "2021-09-21",
                        originalUrlList:[{id:0,url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',},{id:1,url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',},{id:2,url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',},],
                        pretreatmentUrlList:[{id:0,url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',},{id:1,url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',},{id:2,url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',},],
                        summary: "我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容",
                        textSummary:"",
                        report: {}
                    },
                    {
                        id:"",
                        name: "李四",
                        time: "2021-09-23",
                        originalUrlList:[{id:0,url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',},{id:1,url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',},{id:2,url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',},],
                        pretreatmentUrlList:[{id:0,url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',},{id:1,url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',},{id:2,url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',},{id:3,url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',},],
                        summary: "是内容我是内容我是内容我是内容我是内容我是内是内容我是内容我是内容我是内容我是内容我是内是内容我是内容我是内容我是内容我是内容我是内是内容我是内容我是内容我是内容我是内容我是内是内容我是内容我是内容我是内容我是内容我是内是内容我是内容我是内容我是内容我是内容我是内是内容我是内容我是内容我是内容我是内容我是内是内容我是内容我是内容我是内容我是内容我是内我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容",
                        textSummary:"",
                        report: {}
                    },
                ],
                isShow: true,
                common:{header:"分析概述",footer:">>>查看详情"},
            }
        },
        methods: {
            //完成按钮
            complete(){
                //跳转页面
                this.$router.push({name:'CustomerManager'})
            },
            //查看详情按钮
            viewDetails(val){
                this.$router.push({name:'AnalysisReport',params: val})
            },
            download() {
                //下 载
                let array = [];
                for (let i = 0; i < this.users.length; i++) {
                    let id = "id" + i;
                    array[i] = {id:this.users[i].id}
                }
                api.downReport(array).then(res => {
                    const content = res
                    const blob = new Blob([content],{ type: "application/zip" })
                    const fileName = '性格报告'
                    if('download' in document.createElement('a')) { // 非IE下载
                        const elink = document.createElement('a')
                        elink.download = fileName
                        elink.style.display = 'none'
                        elink.href = URL.createObjectURL(blob)
                        document.body.appendChild(elink)
                        elink.click()
                        URL.revokeObjectURL(elink.href) // 释放URL 对象
                        document.body.removeChild(elink)
                    } else { // IE10+下载
                        navigator.msSaveBlob(blob, fileName)
                    }
                    this.$message.success("下载成功");
                }).catch(() => {
                    this.$message.error("下载失败");
                });
            },
            repeatAnalysis() {
                //再 次 分 析
                let array = [];
                for (let i = 0; i < this.users.length; i++) {
                    let id = "id" + i;
                    array[i] = {id:this.users[i].id}
                }
                api.repeatAnalysis(array).then(res => {
                    //返回数据或者跳转页面
                    this.$message.success("分析成功");
                }).catch(() => {
                    this.$message.error("分析失败");
                });
            },
            //检查总结长度不能超过预期
            checkedSummary(){
                let users = this.users;
                for (let i = 0; i < users.length; i++) {
                    console.log(i)
                    if (users[i].summary.length > 180){
                        this.users[i].textSummary = users[i].summary.substring(0, 176) + ". . . . . .";
                    }else {
                        this.users[i].textSummary = users[i].summary;
                    }
                }
            },
            getNotAnalysisData() {
              // var arr = JSON.parse(this.$route.params.array);
              // var selectAnaId = this.$route.params.anaId;
              // console.log("进入了方法")
              // console.log(arr)
              //
              // let array = [];
              // for (let i = 0; i < arr.length; i++) {
              //   let id = {};
              //   id.id = arr[i];
              //   array[i] = id;
              // }
              // array = {array}
              // console.log(array);
              // console.log(selectAnaId);
              //
              //
              // customer.batchAnaly(array,selectAnaId).then(response => {
              //   this.users = response.data.list
              // })
              // console.log("进入了批量处理方法")
              // console.log(this.users)

              // this.users = JSON.parse(this.$route.params.list)
                this.checkedSummary();
            },
        },
        created() {
            //初始化
            this.getNotAnalysisData();
        },
    }
</script>

<style scoped>
    .summary-header{
        font-size: 25px;
        text-align: center;
        color: #01A7F0;
    }
    .summary-content {
        margin: 20px 60px;
        font-size: 16px;
        font-weight: bold;
    }
    .summary-footer{
        display: inline-block;
        position: absolute;
        top: 310px;
        right: 20px;
        bottom: 0;
        font-size: 16px;
        color: #01A7F0;
    }
    .summary-footer:hover{
        cursor: pointer;
    }
    .my_analysis{
        font-size: 21px;
    }
    .return_button{
        /*display: inline-block;*/
        float: left;
        margin-top: 10px;
    }
    .return_button:hover{
        cursor: pointer;
    }
    .return_p{
        vertical-align: 10px;
        margin-left: 2px;
        display: inline-block;
    }
    .my_analysis_title {
        /*display: inline-block;*/
        margin-left: 150px;
    }

    .my_analysis > div > strong {
        font-size: 40px;
        color: #01A7F0;
    }

    .my_analysis_title > p {
        display: inline-block;
        font-size: 25px;
        vertical-align: 1px;
        color: #01A7F0;
    }

    .my_analysis_title > div {
        display: inline-block;
    }

    .my_analysis_title > div>div {
        display: inline-block;
        font-size: 15px;
        margin-left: 30px;
    }

    .report_container1 {
        margin: 20px 150px 35px 150px;
        background: #f5f5f5;
        padding: 20px;
        border: 2px solid #ddd;
        border-radius: 2%;
    }

    .report_container2 {
        position: relative;
        border: 2px solid #ddd;
        height: 325px;
        padding: 10px;
        margin: 20px;
        border-radius: 2%;
    }
    .batch_conten1{
        display: inline-block;
        margin-left: 50px;
        margin-top: 100px;
    }
    .batch_conten2{
        display: inline-block;
    }
    .img_p{
        display: inline-block;
        margin-left: 12px;
        vertical-align: 5px;
    }
    .batch_icon{
        font-size: 30px;
    }
    .batch_conten1_date{
        margin-top: 20px;
        text-align: center;
    }
    .image_footer {
        text-align: center;
        margin-top: 40px;
        margin-bottom: 50px;
    }

    .my_button {
        margin-left: 100px;
    }
    .my_button_size{
        width: 251px;
        margin-top: 20px;
    }

    .original {
        display: inline-block;
        position: absolute;
        top: 40px;
        right: 0;
        bottom: 0;
        left: 240px;
        width: 380px;
        height: 260px;
        border: 3px solid #ddd;
        border-radius: 5%;
    }

    .pretreatment {
        display: inline-block;
        position: absolute;
        top: 40px;
        right: 0;
        bottom: 0;
        left: 680px;
        width: 380px;
        height: 260px;
        border: 3px solid #ddd;
        border-radius: 5%;
    }

    .summary {
        display: inline-block;
        position: absolute;
        top: 40px;
        right: 0;
        bottom: 0;
        left: 680px;
        width: 420px;
        height: 260px;
    }

    .my_analysis_image {
        margin: 13px;
    }

    .fade-enter-from,
    .fade-leave-to {
        opacity: 0;
        transform: translateY(80px);
    }

    .fade-enter-active,
    .fade-leave-active {
        transition: all 0.6s ease;
    }


    /*两个搭配使用，能够实现后续列表渐渐飘上来的效果*/
    .fade-move {
        transition: all 0.6s ease;
    }

    .fade-leave-active {
        position: absolute;
    }
</style>